package com.kolon.business.mOI.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mOI.controller.MOIExecSuggestionWriteController")
public class MOIExecSuggestionWriteController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mOI/mOIExecSuggestionWrite.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 리턴 URL
		String returnUrl = request.getContextPath() + 
			"/business/mOI/mOI.do";
		// 회원정보 세션
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String userId = (String)userMap.get("userId");
		String userPw = (String)userMap.get("userPw");
		String cpyCD = (String)userMap.get("CompanyCD");
		// 파라미터
		String Title = ComUtil.nullChk(request.getParameter("Title"), "");
		String htmlbody = ComUtil.nullChk(request.getParameter("htmlbody"), "");
		String JudgeDeptCD = (String)userMap.get("DeptCode");
		String SugFlag = ComUtil.nullChk(request.getParameter("SugFlag"), "A00001");
		String StartDate = ComUtil.nullChk(request.getParameter("StartDate"));
		String EndDate = ComUtil.nullChk(request.getParameter("EndDate"));
		String JoinerWeight = ComUtil.nullChk(request.getParameter("JoinerWeight"));
		String Status = ComUtil.nullChk(request.getParameter("Status"));
		String Reson = ComUtil.nullChk(request.getParameter("Reson"));
		String YearEff = ComUtil.nullChk(request.getParameter("YearEff"));
		String ThisYearEff = ComUtil.nullChk(request.getParameter("ThisYearEff"));
		String YearEff2 = ComUtil.nullChk(request.getParameter("YearEff2"));
		String ThisYearEff2 = ComUtil.nullChk(request.getParameter("ThisYearEff2"));
		// XML DOCUMENT 및 인증 처리
		StringBuffer buffer = new StringBuffer();
		buffer.append(url);
		buffer.append("/oi_suggestion.aspx?strGubun=ExecReg&mode=1");
		buffer.append("&Title=").append(ComUtil.getEncode(Title, "EUC-KR"));
		buffer.append("&htmlbody=").append(ComUtil.getEncode(htmlbody, "EUC-KR"));
		buffer.append("&StartDate=").append(StartDate);
		buffer.append("&EndDate=").append(EndDate);
		buffer.append("&JoinerWeight=").append(ComUtil.getEncode(JoinerWeight, "EUC-KR"));
		buffer.append("&AcceptEnergy=").append("");
		buffer.append("&Status=").append(Status);
		buffer.append("&Reson=").append(ComUtil.getEncode(Reson, "EUC-KR"));
		buffer.append("&YearEff=").append(YearEff);
		buffer.append("&ThisYearEff=").append(ThisYearEff);
		buffer.append("&YearEff2=").append(YearEff2);
		buffer.append("&ThisYearEff2=").append(ThisYearEff2);
		buffer.append("&SugFlag=").append(SugFlag);
		buffer.append("&JudgeDeptCD=").append(JudgeDeptCD);
		buffer.append("&Seq=").append("");
		buffer.append("&ESeq=").append("");
		buffer.append("&KeepFlag=").append("R");
		buffer.append("&ThemeSeq=").append("");
		buffer.append("&a_pmode=").append("elist");		
		buffer.append("&a_amode=").append("input");
		buffer.append("&chkSecurity=").append("1");
		buffer.append("&companycd=").append(cpyCD);
		ComUtil.getDocument(buffer.toString(), userId, userPw);
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("message", "등록되었습니다.");
		modelAndView.addObject("scriptType", "003");
		modelAndView.addObject("message_url", returnUrl);
		modelAndView.setViewName("/business/common/alert");
		return modelAndView;
	}

}
